package logic

import (
	"context"
	"gozerogateway/rpc/model/appmodel"
	"gozerogateway/rpc/tenant/internal/svc"
	"gozerogateway/rpc/tenant/tenantclient"

	"encoding/json"
	"github.com/zeromicro/go-zero/core/logx"
)

type AppDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAppDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppDetailLogic {
	return &AppDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

//one table

//type AppDetailDo struct {
//	//Info *svcmodel.GatewayServiceInfo `json:"info"` //base info
//	//
//	//HTTPRule      *svcmodel.GatewayServiceHttpRule      `json:"http_rule"` //rule
//	//TCPRule       *svcmodel.GatewayServiceTcpRule       `json:"tcp_rule"`
//	//GRPCRule      *svcmodel.GatewayServiceGrpcRule      `json:"grpc_rule"`
//	//LoadBalance   *svcmodel.GatewayServiceLoadBalance   `json:"load_balance"`
//	//AccessControl *svcmodel.GatewayServiceAccessControl `json:"access_control"`
//}
func (l *AppDetailLogic) AppDetail(in *tenantclient.AppDetailReq) (*appmodel.GatewayApp, error) {
	// todo: add your logic here and delete this line

	res, err := l.svcCtx.AppModel.FindOne(l.ctx, in.ID)
	if err != nil {
		reqStr, _ := json.Marshal(in)
		logx.WithContext(l.ctx).Errorf("根据id查询app表信息失败,参数:%s,异常:%s", reqStr, err.Error())
		return nil, err
	}
	return res, nil
}
